/*! \file textarea.h	
	This is the header file for textarea.cpp
	
	This contains the TextArea class
	
	This will currently only display text on multiple lines.
*/

#ifndef TEXT_AREA_H
#define TEXT_AREA_H

#include <map>
#include <vector>
#include "textcomp.h"

using namespace std;


/**
	\class TextArea

	This holds rows of text and is meant to be put in a ScrollPanel.
*/
class TextArea : public TextComponent {
private:

	/**
	* This is used by setText and appendText. This function modifies textRows
	* and h, and also calls resized (which make an onSize event and tells the parent)
	*/
	void setTextHelper( string t );

	/**
	* This is the width of the textArea without the border
	* (widthWithoutBorder = w - 2 * borderWidth)
	*/
	int widthWithoutBorder;

	/**
	* This keeps track of each row of text in the TextArea.
	* They do not have '\n's in them.
	* Also, TextArea still uses buffer to keep track of the string with
	* '\n's so that resizing the TextArea keeps the same line-structure.
	* For example, if you append a new line to a chat log and then resize, you'd still
	* want that text to be on its own line.
	*/
	vector<string> textRows;
public:
	/**
	* Constructor
	*/
	TextArea( Component* parent );

	/**
	* This modifies the width and the widthWithoutBorder, but more importantly, it also
	* calls setText with the current buffer as an argument. By doing this, it will recalculate
	* how the text is laid out in case words need to be shifted to different lines.
	*
	* Also, this is called by a parent (at least a ScrollPanel does this) when the parent's width is changed.
	*/
	void setWidth( int newW );

	/**
	* This clears textRows and the current buffer, and sets the text to t.
	*/
	void setText( string t );

	/**
	* This doesn't clear textRows or the current buffer, but rather just adds a newline to
	* buffer, appends the text, and calculates only where the new text should go.
	*/
	void appendText( string a );
	
	/**
	* This draws the TextArea
	*/
	void draw();
	
	/**
	* This sends an onSize event to all its listeners, and also tells the parent that
	* this changed size.
	*/
	void resized();
	
	/**
	* Strictly an accessor right now.
	* Returns the buffer that this has. The buffer does not have newlines in it.
	*/
	string getText() {
		return buffer;
	}
};



#endif
